package tasks 
{
	import app.textures.TextureInfo;
	import app.textures.TexturePartInfo;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class LoadTextureParts extends BaseXmlLoadTask
	{
		private var _textureInfo:TextureInfo;
		
		public function LoadTextureParts(xmlFile:String, textureInfo:TextureInfo) 
		{
			super(xmlFile);
			_textureInfo = textureInfo;
		}
		
		override protected function onXMLReaded(xml:XML):void 
		{
			var xmlList:XMLList = xml.part;
			var count:int = xmlList.length();
			
			var texture:TextureInfo;
			try
			{
				for (var i:int =0; i < count; i++)
				{
					_textureInfo.addTexturePart(new TexturePartInfo(xmlList[i].attribute("size"),
																	xmlList[i].attribute("url")));
				}
			}catch(err:Error)
			{
				handleError("Error while XML: " + err.errorID + "; " + err.name + "; "  + err.message);
				complete(false);
				return;
			}
			complete(true);
		}
		
		override public function destroy():void 
		{
			_textureInfo = null;
			super.destroy();
		}
		
	}

}